function SingleUser(name,age){
  this.name = name;
  this.age = age;
}
//闭包实现仅访问一个对象
SingleUser.getInstance = (function () {
 let instance = null;
 return function (name, age) {
     if (!instance){
         instance = new SingleUser(name,age);
     }
     return instance;
 }
})()


let demo1 = SingleUser.getInstance("单例one",6);
  let demo2 = SingleUser.getInstance("单例tow",7);


  console.log(SingleUser.getInstance)
  console.log(demo1)

  console.log(demo2)


  
class SingletonSchool {
    constructor(name, clsGrade, studentNumber) {
        this.name = name;
        this.clsGrade = clsGrade;
        this.studentNumber = studentNumber;
    }
    //静态方法
    static getInstance(name, clsGrade, studentNumber) {
        if(!this.instance) {
            this.instance = new SingletonSchool(name, clsGrade, studentNumber);
        }
        return this.instance;
    }
}

let demo5 = SingletonSchool.getInstance("四川小学","1年级","500人")
  let demo6 = SingletonSchool.getInstance("重庆小学","1年级","600人")
  console.log("demo5：",demo5
      ,"demo6:",demo6
      ,"demo5 == demo6:",(demo5 == demo6)
  )
